'''
一阶字典读
'''
def getElement_twolevel(dic, key1, key2):
	if dic.has_key(key1):
		if dic[key1][0] == 0:
			return 0.0
		if dic[key1].has_key(key2):
			return 1.0 * dic[key1][key2] / dic[key1][0]
	return 0.0
'''
一阶字典写
'''
def getElement_onelevel(dic, key):
	if dic[0] == 0:
		return 0.0
	if dic.has_key(key):
		return 1.0 * dic[key] / dic[0]
	return 0.0
'''
二阶字典写
'''
def addElement_twolevel(dic, key1, key2, value):
	if not dic.has_key(key1):
		dic[key1] = {}
		dic[key1][key2] = value
		dic[key1][0] = value
	else:
		if not dic[key1].has_key(key2):
			dic[key1][key2] = value
			dic[key1][0] += value
		else:
			dic[key1][key2] = dic[key1][key2] + value
			dic[key1][0] += value
